<?php 
//引进配置信息
include 'include/init.php';
//引入数据库配置信息
include 'include/mysql.config.php';
//引入公共函数

include 'include/common.fun.php';

include 'data/common_data.php';



if($_POST){
  $username = $_POST['username'];
  $password = $_POST['password'];
    // 数据的验证

    

  if ($username==""&&$username==null) {
    alert('用户名不能为空');exit;
  }
  if ($password==""&&$password==null) {
    alert("密码不能为空");exit;
  }
  $code=strtoupper($_POST['code']);
  session_start();
  if ($code!=$_SESSION['code']) {
    alert('验证码错误');exit;
  }
  // if($password1 !== $password){
  //   echo '密码不相同';
  //   die;
  // }
  if (file_exists('user.txt')) {
    $info=file('user.txt');
    foreach($info as $k=> $v){
      $v = trim($v);
      if(!empty($v)){
        $tmp = iconv('gbk','utf-8',$v);
        $new = explode('#@#',$tmp);
        if($username == $new[0]){
          alert('用户名已经存在');
          exit;
        }
      }
    }
  	$date=array(
  		'user_name'=>$username,
  		'user_password'=>md5($password)
  		);
  	$db->insert('wd_user',$date);
  }
  


  $str = $username.'#@#'.md5($password).'#@#'.$sex.'#@#'.$city."\r\n";
  $str = iconv('utf-8','gbk',$str);
  file_put_contents('user.txt', $str,FILE_APPEND);
  alert('注册成功','user_login.php');
}


//加载视图页面
include 'view/user_reg.php';



